﻿using my_newconsole;
using my_newconsole.Dtos;
using my_newconsole.Report;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;

M08();

void M01()
{
    var ww = new string[] { "1", null, "35" };
    Console.WriteLine(string.Join('|', ww));
}

void M02()
{
    var xml =
        @"<?xml version=""1.0"" encoding=""utf-8""?>
<root>
	<!--检查号-->
	<accessionNumber>检查号</accessionNumber>
	<!--开始时间-->
	<startTime>开始时间</startTime>
	<!--结束时间-->
	<endTime>结束时间</endTime>
</root>";
    xml = Regex.Replace(xml, @"<\?xml.+\?>", "").Trim();
    var doc = new XmlDocument();
    doc.LoadXml(xml);
    var json = JObject.Parse(JsonConvert.SerializeXmlNode(doc));
    var obj = json["root"];
    var dd = obj.ToObject<C01>();
    Console.WriteLine(JsonConvert.SerializeObject(dd));
}

void M03()
{
    // \u007f
    var json = JObject.Parse(File.ReadAllText("./1.json"));
    var aaa = json["Impression"].Value<string>();
    var www = aaa.Replace("\u007f", "");
    System.Console.WriteLine(aaa);
    System.Console.WriteLine(www);
}

void M04()
{
    var ww = "ZY__556852";
    var aa = ww.Split(new[] { "ZY__" }, StringSplitOptions.None)[1];
    System.Console.WriteLine(aa);
}

void M05()
{
    var aa = new C02 { Name = "孙小双", Age = 33 };
    var xsArr = new XmlSerializer(typeof(C02));
    var writer = new StringWriter();
    var defaultNamespace = new XmlSerializerNamespaces();
    defaultNamespace.Add("", "");
    xsArr.Serialize(writer, aa, defaultNamespace);
    Console.WriteLine("数组对象序列化: " + writer.ToString());
}

void M06()
{
    #region 冠状动脉
    // var html = File.ReadAllText("./GZDM.txt");
    // var aa = new GZDM_Structural(new HISRISReportDTO { ReportContent = html }).Generate();
    // File.WriteAllText("./GZDM-detal2.xml", aa.ToXml());
    #endregion

    #region 下肢动脉
    var html = File.ReadAllText("./XZDM.txt");
    var aa = new XZDM_Structural(new HISRISReportDTO { ReportContent = html }).Generate();
    File.WriteAllText("./XZDM-detal2.xml", aa.ToXml());
    #endregion

    #region 头颈部
    // var html = File.ReadAllText("./TJB.txt");
    // var aa = new TJB_Structural(new HISRISReportDTO { ReportContent = html }).Generate();
    // File.WriteAllText("./TJB-detal2.xml", aa.ToXml());
    #endregion

    #region 脑组织
    // var html = File.ReadAllText("./NZZ.txt");
    // var aa = new NZZ_Structural(new HISRISReportDTO { ReportContent = html }).Generate();
    // File.WriteAllText("./NZZ-detal2.xml", aa.ToXml());
    #endregion

    // File.WriteAllText("./XZDM.json", JsonConvert.SerializeObject(XZDM_Structural.Indexs));

    // Console.WriteLine(JsonConvert.SerializeObject(GZDM_Structural.Indexs));
}

void M07()
{
    var content = File.ReadAllText("./usreport.txt");
    Console.WriteLine(content);

    content = content.Replace("：", ":");
    var arr = content.Split('\n');
    var list = new List<ParmDetail>();
    var num = 0;
    foreach (var item in arr)
    {
        num++;
        var keyValue = item.Trim('\r').Split(':');
        if (keyValue.Length == 1)
        {
            keyValue = keyValue[0].Split(' ');
        }
        var key = keyValue[0];
        var val = keyValue.Length > 1 ? keyValue[1] : "";
        list.Add(
            new ParmDetail
            {
                ParmItemNo = key,
                ParmEngName = key,
                ParmChnName = key,
                ParmValue = val,
                ParmSortNo = num.ToString(),
                Remark = ""
            }
        );
    }
    var para = new ParmDetails { ParmDetail = list };
    Console.WriteLine(para.ToXml());
}

void M08()
{
    var dd = new decimal(3.4);
    System.Console.WriteLine(dd.GetType().Name);
    System.Console.WriteLine(dd);
    // var cc = (double)dd;
    var cc = double.Parse("");
    System.Console.WriteLine(cc.GetType().Name);
    System.Console.WriteLine(cc);
}
